<?php echo $this->Session->flash(); ?>
<h1>UNIDADES FISIOGRAFICAS DEL PREDIO <?php echo $this->Session->read('predio_codigo'); ?></h1>
<div id="loading" style="display: none;">
    <?php echo $html->image('loading.gif', array('border' => "0", 'align' => 'center')); ?>
</div>
<table  id="tabla">
    <thead>
        <tr>
            <th>Unidad fisiografica</th>
            <th>Área (ha)</th>
            <th>Porcentaje</th>
            <th>Valor total</th>
            <th>Clase Agrológica</th>
            <th>Útil</th>
            <th colspan="2"></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 1;
        $valorTotal = 0;
        foreach ($unidades as $unidad):
            $valorTotal += ($unidad['EvaluationPhysiographicUnit']['valor_unitario'] * $unidad['EvaluationPhysiographicUnit']['area']);
            ?>
            <tr>
                <td><?php echo "Unidad fisiografica " . $i ?></td>
                <td><?php echo $unidad['EvaluationPhysiographicUnit']['area'] ?></td>
                <td><?php
        if ($areaTotal > 0)
            echo number_format((($unidad['EvaluationPhysiographicUnit']['area'] * 100 ) / $areaTotal), 4, ',', '.') . " %"
                ?></td>
                <td><?php echo "$ " . number_format(($unidad['EvaluationPhysiographicUnit']['valor_unitario'] * $unidad['EvaluationPhysiographicUnit']['area']), 0, ',', '.') ?></td>
                <td><?php echo $unidad['EvaluationPhysiographicUnit']['clase_agrologica'] ?></td>
                <td><?php echo $unidad['EvaluationPhysiographicUnit']['util'] ?></td>
                <td><?php echo $ajax->link('Editar', array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'edit', $unidad['EvaluationPhysiographicUnit']['id']), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading', 'escape' => false)); ?></td>
                <td><?php echo $ajax->link('Eliminar', array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'delete', $unidad['EvaluationPhysiographicUnit']['id'], $appraisal_id), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading', 'escape' => false), '¿Realmente desea eliminar el registro?'); ?></td>
            </tr>
            <?php
            $i++;
        endforeach;
        $error = ((round($areaTotal, 4) != round($areaAvaluo, 4)) or $areaAvaluo < 0 or empty($areaAvaluo) ) ? true : false;
        ?>
        <tr>
            <td><b>Las áreas de las unidades suman:</b></td>
            <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?> ><b><?php echo number_format($areaTotal, 4, ',', '.') . '(ha)' ?></b></td>
            <td></td>
            <td><b><?php echo '$' . number_format($valorTotal, 0, ',', '.') ?></b></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td><b>El área en el avalúo es:</b></td>
            <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>><b><?php echo $areaAvaluo . '(ha)' ?></b></td>
            <td></td>
            <td><b></b></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
</table>
<br>

<table width="100%" border="0"  CellSpacing=10  align="center" >
    <tbody>
        <tr>
            <td>
                <?php echo $ajax->link('Adicionar', array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'add', $appraisal_id), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading', 'escape' => false)); ?>
            </td> 
            <td><?php echo $ajax->link($html->image('regresar.gif', array('width' => '30', 'heigth' => '30', 'alt' => 'Regresar', 'title' => 'regresar')), array('controller' => 'EvaluationAppraisals', 'action' => 'index', $idProperty), array('update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading', 'escape' => false)); ?></td>
            <td><?php echo $ajax->link("Regresar a evaluación inicial" . $html->image('regresar.gif', array('width' => '30', 'heigth' => '30', 'alt' => 'Regresar', 'title' => 'regresar')), array('controller' => 'Properties', 'action' => 'initial_evaluation_index'), array('update' => 'lista_predios', 'complete' => 'cargar()', 'indicator' => 'loading', 'escape' => false));
                ?></td>
        </tr>
    </tbody>
</table>